package o;

import androidx.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class c {
    private static c ˋ;
    private final Deque<fks> ʻ = new ArrayDeque();
    private final Deque<fks> ʽ = new ArrayDeque();
    private final Deque<fks> ˊ = new ArrayDeque();
    @Nullable
    private ExecutorService ˎ;
    @Nullable
    private Runnable ˏ;
    private int ॱ = 64;

    private c() {
    }

    public static c ˊ() {
        if (ˋ == null) {
            synchronized (c.class) {
                if (ˋ == null) {
                    ˋ = new c();
                }
            }
        }
        return ˋ;
    }

    private synchronized ExecutorService ˋ() {
        if (this.ˎ == null) {
            this.ˎ = Executors.newSingleThreadExecutor(ˎ("HwSkinner Dispatcher", false));
        }
        return this.ˎ;
    }

    private ThreadFactory ˎ(final String str, final boolean z) {
        return new ThreadFactory(this) {
            final /* synthetic */ c ˏ;

            public Thread newThread(Runnable runnable) {
                Thread thread = new Thread(runnable, str);
                thread.setDaemon(z);
                return thread;
            }
        };
    }

    public synchronized void ˏ(@Nullable Runnable runnable) {
        this.ˏ = runnable;
    }

    public synchronized void ˏ(fks o_fks) {
        if (this.ʽ.size() < this.ॱ) {
            this.ʽ.add(o_fks);
            ˋ().execute(o_fks);
        } else {
            this.ˊ.add(o_fks);
        }
    }

    private void ˎ() {
        if (this.ʽ.size() < this.ॱ && !this.ˊ.isEmpty()) {
            Iterator it = this.ˊ.iterator();
            while (it.hasNext()) {
                fks o_fks = (fks) it.next();
                it.remove();
                if (!o_fks.ˋ().ʽ()) {
                    this.ʽ.add(o_fks);
                    ˋ().execute(o_fks);
                }
                if (this.ʽ.size() >= this.ॱ) {
                    return;
                }
            }
        }
    }

    public synchronized void ˊ(fks o_fks) {
        this.ʻ.add(o_fks);
    }

    public void ˋ(fks o_fks) {
        ˏ(this.ʽ, o_fks, true);
    }

    public void ˎ(fks o_fks) {
        ˏ(this.ʻ, o_fks, false);
    }

    private <T> void ˏ(Deque<T> deque, T t, boolean z) {
        synchronized (this) {
            if (deque.remove(t)) {
                if (z) {
                    ˎ();
                }
                int ˏ = ˏ();
                Runnable runnable = this.ˏ;
            } else {
                throw new AssertionError("Call wasn't in-flight!");
            }
        }
        if (ˏ == 0 && runnable != null) {
            runnable.run();
        }
    }

    public synchronized int ˏ() {
        return this.ʽ.size() + this.ʻ.size();
    }
}
